//
//  BSAnimation.m
//  Spriter_forCocs2d
//
//  Created by Yang Bean on 13/4/15.
//
//

#import "BSAnimation.h"
#import "BSMainLine.h"
#import "BSTimeLine.h"
@implementation BSAnimation
@synthesize mainline = m_mainLine;
- (id)initWithId:(int)animationId
            name:(NSString*)name
          length:(int)lebgth
          isLoop:(int)loop
{
    self = [super init];
    if (self) {
        m_timelines = [[NSMutableDictionary alloc] init];
        m_id = animationId;
        m_name = [name retain];
        m_length = lebgth;
        m_looping = loop;
    }
    return self;
}
- (void)dealloc
{
    NSLog(@"dealoc animation");
    [m_timelines release];
    [m_name release];
    [super dealloc];
}
- (void)addTimeLine:(BSTimeLine*)timeline key:(NSString*)key
{
    [m_timelines setObject:timeline forKey:key];
}
- (NSString*)name
{
    return m_name;
}
- (int)animationID
{
    return m_id;
}
- (int)length
{
    return m_length;
}
- (BOOL)isLooping
{
    return m_looping;
}
- (NSArray*)timelines
{
    NSMutableArray* array = [[NSMutableArray alloc] init];
    NSEnumerator *enumerator = [m_timelines keyEnumerator];
    id aKey = nil;
    while ( (aKey = [enumerator nextObject]) != nil) {
        [array addObject:[m_timelines objectForKey:aKey]];
    }
    return [array autorelease];
    
}
- (NSString *)description
{
    return [NSString stringWithFormat:@"id = %d, name = %@, len = %d, loop = %d, mainline = %@, timeline = %@",
            m_id, m_name, m_length, m_looping, m_mainLine, m_timelines];
}
- (BSTimeLine*)timelinsWithTimelineID:(int)tid
{
    return [m_timelines objectForKey:[NSString stringWithFormat:@"%d", tid]];
}

@end
